package com.venue.task;

import com.venue.constant.TimeConstant;
import com.venue.service.PLAService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 定时器
 * @author XuJijun
 * 
 */
@Component
public class Scheduler {
	protected final Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	PLAService plaService;
	
	@Scheduled(cron="0 0/1 * * * ?") //每分钟执行一次
	public void statusCheck() {    
		logger.info("每分钟执行一次。开始……");
		//statusTask.healthCheck();
		//logger.info("每分钟执行一次。结束。");
	}  

	@Scheduled(fixedRate=10000)
	public void testTasks() {    
		String hourTime = plaService.getHourTime();
		if("".equals(TimeConstant.dateTime)){
			TimeConstant.dateTime = hourTime;
			plaService.sendFromWhere("-1",hourTime);
			plaService.sendAgesStatic("-1",hourTime);
			plaService.sendSexStatic("-1",hourTime);
			plaService.sendPersonNumHisStatic("-1",hourTime.substring(0,11)+"00:00:00",hourTime);
		}else if(!hourTime.equals(TimeConstant.dateTime)){
			TimeConstant.dateTime = hourTime;
			plaService.sendFromWhere("-1",hourTime);
			plaService.sendAgesStatic("-1",hourTime);
			plaService.sendPersonNumHisStatic("-1",hourTime.substring(0,11)+"00:00:00",hourTime);
			plaService.sendSexStatic("-1",hourTime);
		}

		String realTime = plaService.getRealTime();
		if("".equals(TimeConstant.realTime)){
			TimeConstant.realTime = realTime;
			plaService.sendHeadMapData("-1",realTime);

			plaService.sendPersonNumWarn("-1");
		}else if(realTime!=null && !realTime.equals(TimeConstant.realTime)){
			TimeConstant.realTime = realTime;
			plaService.sendHeadMapData("-1",realTime);

			plaService.sendPersonNumWarn("-1");
		}

		//logger.info("每20秒执行一次。结束。");
	}

}
